package com.gosophia.conferenceManagement.scheme.ws.test.integrate;

import java.util.List;

import junit.framework.Assert;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.transaction.annotation.Transactional;

import com.gosophia.commons.exception.BusinessException;
import com.gosophia.commons.exception.ConcurrencyException;
import com.gosophia.commons.exception.ParameterException;
import com.gosophia.commons.exception.TechnicalException;
import com.gosophia.conferenceManagement.scheme.dto.SchemeJobDataDTO;
import com.gosophia.conferenceManagement.scheme.ws.ConferenceSchemeWebService;
import com.gosophia.taskManagement.dto.JobDTO;
import com.gosophia.userManagement.dto.UserInfoDTO;

@ContextConfiguration(locations = { "classpath*:moduleContext.xml",
"classpath:applicationContext-it.xml" })
@Transactional(rollbackFor = { BusinessException.class })
public class ITConferenceSchemeWebServiceImpl extends AbstractTransactionalJUnit4SpringContextTests{

	@Autowired
	private ConferenceSchemeWebService conferenceSchemeWebService;
	
	@Test
	public void testfindFinishedSchemeApprovalHistoryRecordByJobId() throws BusinessException{
		List<JobDTO> list = conferenceSchemeWebService.findFinishedSchemeApprovalHistoryRecordByJobId(2L);
		Assert.assertEquals(1, list.size());
	}
	@Test(expected = IllegalArgumentException.class)
	public void testUpdateSchemeJobDataWithNull() throws BusinessException{
		conferenceSchemeWebService.updateSchemeJobData(null);
	}
	
	@Test(expected = IllegalArgumentException.class)
	public void testUpdateSchemeJobDataWithJobIdNull() throws BusinessException{
		SchemeJobDataDTO s = new SchemeJobDataDTO();
		JobDTO j = new JobDTO();
		s.setJobDTO(j);
		conferenceSchemeWebService.updateSchemeJobData(s);
	}
	@Test
	public void testUpdateSchemeJobData() throws BusinessException {
		SchemeJobDataDTO schemeJobData = new SchemeJobDataDTO();
		schemeJobData.setOpinion("my opinion");
		UserInfoDTO user = new UserInfoDTO();
		user.setUserInfoId(2L);
//		schemeJobData.setNextApproval(user);
		JobDTO job = new JobDTO();
		job.setJobId(2L);
		schemeJobData.setJobDTO(job);
		conferenceSchemeWebService.updateSchemeJobData(schemeJobData);
		SchemeJobDataDTO updated = conferenceSchemeWebService.findSchemeJobDataDTOByJobId(2L);
		Assert.assertEquals("my opinion", updated.getOpinion());
	}

}
